package com.xdap.keymen.service.dayang;

import com.definesys.mpaas.query.MpaasQuery;
import com.xdap.keymen.entity.dayang.DaYangStoreValueOrderEntity;
import com.xdap.motor.entity.SnowflakeIdWorker;
import com.xdap.runtime.service.RuntimeAppContextService;
import com.xdap.runtime.service.RuntimeDatasourceService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class DaYangStoreValueOrderService {
    private final RuntimeDatasourceService runtimeDatasourceService;
    private final RuntimeAppContextService runtimeAppContextService;
    private final SnowflakeIdWorker snowflakeIdWorker;

    /**
     * 根据储值订单号查询订单
     *
     * @param storedValueOrderId 储值订单号
     * @return 订单信息
     */
    public DaYangStoreValueOrderEntity getOrderDetail(String storedValueOrderId) {
        String currentTenantId = runtimeAppContextService.getCurrentTenantId();
        MpaasQuery query = runtimeDatasourceService.buildTenantMpaasQuery("xdap_app_" + currentTenantId);
        query.eq("stored_value_orderid", storedValueOrderId);
        return query.doQueryFirst(DaYangStoreValueOrderEntity.class);
    }


}
